public class testjava {
    public static void main(String[] args) {
        System.out.println("Hello World!");
        int[] array = {1, 21, 3, 11, 15, 6, 7, 122};
        int[] mp = mp(array, 7);
        System.out.println("结果是：");
        for (int i : mp) {
            System.out.println(i);
        }
    }

    static int[] mp(int[] a, int n) {
        int i,j;
        for (i=0; i<n; i++) { //表示n次排序过程
            for (j=1; j<n-i; j++) {
                if (a[j-1] > a[j]) { //前面的数字大于后面的数字就交换
                    //交换a[j-1]和a[j]
                    int temp;
                    temp = a[j-1];
                    a[j-1]=a[j];
                    a[j]=temp;

                }
            }
        }
        return a;
    }

}


class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");
        int[] array = {1, 2, 3, 4, 5, 6, 7};
        int result = biSearch(array, 7);
        System.out.println("result:" + result);
    }

    static int biSearch(int[] array, int a) {
        int lo= 0;
        int hi = array.length - 1;
        int mid;
        while(lo <= hi) {
            mid=(lo+hi)/2;//中间位置
            if(array[mid]==a) {
                return mid+1;
            } else if(array[mid]<a) {//向右查找
                lo = mid + 1;
            } else {//向左查找
                hi = mid - 1;
            }
        }
        return -1;//找不到
    }


}


